<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>发帖</title>
    <link rel="stylesheet" href="${base}/layui/css/layui.css">
    <link rel="stylesheet" href="${base}/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${base}/css/formSelects-v4.css">
    <link rel="stylesheet" href="${base}/css/admin.css">
    <style>
    	.layui-bg-black{width: 200px;height: 136px;margin-right: 30px;float: left;text-align: center;font-size: 33px;color: #000000!important;padding-top: 30px;}
    	.hide {display: none;}
    	.checkbox{display: inline-block;}
    	.layui-form-item{font-size: 18px;}
    	.width100 {width: 100px;}
    	.discuss{ float: left;margin-left: 30px;padding-top: 6px;}
    	.discuss p{text-align: left; font-size: 13px;margin-top: 5px;padding-top: 2px;}
    	.discuss_img{ float: left;margin-left: 10px;margin-top: 5px;}
    </style>
</head>
<body  class="layui-layout-body" style="overflow:scroll;">
<#include "/common/left.flt">	
<div class="layui-main" style="position: absolute;left: 205px;top: 20px; width: calc(98% - 210px);" >
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
  <legend>发帖</legend>
</fieldset>
<div class="layui-form"  style="padding-top:20px;float: left;width: 60%;">
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">用户</label>
    <div class="layui-input-block">
      <img src="http://qiniu.static.50dufei.top/${users.user_header}" style="border-radius: 50%;" />  <a href="${base}/users_list/detail?user_id=${users.id}" target="_blank" >${users.nick_name} ${users.user_mobile}</a> 
    </div>
  </div>
  <from>
  <div class="layui-form-item">
    <label class="layui-form-label">板块</label>
    <div class="layui-input-block">
      <select name="social" id="social"  >
      	<option value="0">没圈子</option>
      	<#list social_list as one>
        <option value="${one.id}">${one.title}</option>
        </#list>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">话题</label>
    <div class="layui-input-block">
      <select name="topic_id" id="topic_id" xm-select="search-local" xm-select-search>
      	<#list topic_list as one>
        <option value="${one.id}">${one.name}</option>
        </#list>
      </select>
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">内容</label>
    <div class="layui-input-block">
      <textarea name="content" id="content" class="layui-textarea" ></textarea>
    </div>
   </div>
   <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">图片</label>
    <div class="layui-input-block">
    	<button type="button" class="layui-btn" id="upload" ><i class="fa fa-upload" ></i></button>
    </div>
   </div>
   <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">发帖时间</label>
    <div class="layui-input-block">
      <input name="create_time" id="create_time" class="layui-text layui-input" />
    </div>
   </div> 
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
	    <button class="layui-btn" id="save"><i class="fa fa-check"></i> 保存</button>
	</div>
  </div>
  </from>
</div>
<div class="layui-form"  style="padding-top:20px;float: left;width: 37%;    padding-left: 3%;">
	<table class="layui-table" >
		<thead>
	        <tr>
	             <th>内容</th>
	             <th>时间</th>
	        </tr>
	    </thead>
	    <#list history as one>
     	<tr <#if one.create_time gt time>style="background-color:#009688;color:#fff;"</#if>>
     		<td><a href="${base}/navy_user/edit_card?id=${one.id}">${one.content}</a> </td>
     		<td>${one.create_time_string}</td>
     	</tr>
     	</#list>
    </table>
    
</div>
<form action="${base}/util/uploadFile" method="post" name="uploadForm" enctype="multipart/form-data" id="uploadForm" class="hide" >
    <input name="pic" type="file" id="pic" class="hide"/>
</form>
</body>
<script src="${base}/layui/layui.all.js"></script>
<!-- <script src="${base}/js/jquery-2.1.4.min.js" type="text/javascript"></script> -->
<script src="https://unpkg.com/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="${base}/js/jquery.form.js"></script>
<script src="${base}/js/formSelects-v4.min.js" type="text/javascript"></script>
<script type="text/javascript">

layui.use('laydate', function(){
	  var laydate = layui.laydate;
	  //执行一个laydate实例
	  laydate.render({
	    elem: '#create_time'
	    ,type: 'datetime'
	  });
});

var formSelects = layui.formSelects;

formSelects.render('search-local');

var currentPic = null;

var images = "";
$('body').on('click', '#upload', function () {
    currentPic = $(this);
    $("#pic").attr("accept","image/*");
    $("#pic").click();
});
$("#pic").change(function (){
    var fileName = $("#pic").val()
    var options = {
        success:  showResponse,  //处理完成的回调函数
        resetForm: true,
        //dataType:  'json'
    };
    $("#uploadForm").ajaxSubmit(options);
});
$("#save").click(function (){
	var topic_id = formSelects.value('search-local', 'valStr');
	var content = $("#content").val();
	if (images){
		images = images.substring(0,images.length -1 );
	}
	var social = $("#social").val();
	var create_time = $("#create_time").val();
	
	$.post("${base}/navy_user/card_save",
	   		{"topics":topic_id,"user_id":"${user_id}","content":content,"images":images,"social":social,"create_time":create_time},function(data){ 
	   			layer.alert(data);
	   			window.location.reload();
	   			
	   		}
	 );	
	return;
});
function showResponse(data)  {
    console.log(data);
    if(data.error == 0) {
    	currentPic.before("<img src=\"http://qiniu.static.50dufei.top\/"+data.url+"?imageView2/1/w/100/h/100\" />"); 
    	images  = images + data.url + ","; 
    } else {
    	layer.alert(data.message);
    }
   
}


</script>
</html>